﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using IndoReputation.Models.BusinessObject;
using IndoReputation.Models.BusinessObject.Collections;
using IndoReputation.Models.DataAccess;

namespace IndoReputation.Models.BusinessLogic
{
    public class CityBOL
    {
        /// <summary>
        /// Author: Nguyen Duc Thanh Tung
        /// Created on: 4/22/2012  6:03 PM
        /// Todo: Insert an city to db
        /// </summary>
        /// <param name="city">The city.</param>
        /// <returns></returns>
        public static int Insert(City city)
        {
            try
            {
                city.CreateAt = DateTime.Now;
                city.CreateBy = MySession.UserID;
                city.UpdateAt = null;
                city.UpdateBy = null;
                return CityDAL.Insert(city);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        /// <summary>
        /// Author: Nguyen Duc Thanh Tung
        /// Created on: 11/30/2011  9:45 AM
        /// Todo: Update a User Exists in Database 
        /// </summary>
        /// <param name="city">A city.</param>
        /// <returns></returns>
        public static bool Update(City city)
        {
            try
            {
                city.UpdateAt = DateTime.Now; ;
                city.UpdateBy = MySession.UserID;
                return CityDAL.Update(city);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        /// <summary>
        /// Author: Nguyen Duc Thanh Tung
        /// Created on: 11/30/2011  10:36 AM
        /// Todo: Delete a User Existst in Database
        /// </summary>
        /// <param name="city">A city.</param>
        /// <returns></returns>
        public static bool Delete(int cityID)
        {
            try
            {
                return CityDAL.Delete(cityID);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        /// <summary>
        /// Author: Nguyen Duc Thanh Tung
        /// Created on: 11/29/2011  5:23 PM
        /// Todo: Get All City
        /// </summary>
        /// <returns></returns>
        public static CityList GetAllCity()
        {
            try
            {
                return CityDAL.GetAllCity() ?? new CityList();
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        /// <summary>
        /// Author: Nguyen Duc Thanh Tung
        /// Created on: 11/29/2011  5:23 PM
        /// Todo: Get All City
        /// </summary>
        /// <returns></returns>
        public static CityList GetAllCityByCountryID(int countryID)
        {
            try
            {
                return CityDAL.GetAllCityByCountryID(countryID) ?? new CityList();
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        /// <summary>
        /// Author: Nguyen Duc Thanh Tung
        /// Created on: 11/30/2011  10:40 AM
        /// Todo: Select a User existst in Database
        /// </summary>
        /// <param name="cityID">The city ID.</param>
        /// <returns></returns>
        public static City GetCityById(int cityID)
        {
            try
            {
                return CityDAL.GetCityById(cityID);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        /// <summary>
        /// Author: Nguyen Duc Thanh Tung
        /// Created on: 11/29/2011  5:23 PM
        /// Todo: Get All Country
        /// </summary>
        /// <returns></returns>
        public static CityJoinList GetAllCityJoin()
        {
            try
            {
                return CityDAL.GetAllCityJoin() ?? new CityJoinList();
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
    }
}